package homework.day01;

import java.util.Random;
import java.util.Scanner;

public class Test06 {
    public static void main(String[] args) {
        String chs = "abcdefghijklmnqprstuvwxyzABCDEFGHIJKLMNQPRSTUVWXYZ3456789";
        Random random = new Random();
        int length =chs.length();
        StringBuilder buf = new StringBuilder();
        //生成四位验证码
        buf.append(chs.charAt(random.nextInt(length)))
            .append(chs.charAt(random.nextInt(length)))
            .append(chs.charAt(random.nextInt(length)))
            .append(chs.charAt(random.nextInt(length)));
        //将生成的验证码转换为String 类型，为了后续调用忽略大小写比较做准备
        String code = buf.toString();
        System.out.println(code);
        Scanner scan = new Scanner(System.in);
        System.out.println("输入你的验证码：");
        String input =scan.nextLine();
        if (code.equalsIgnoreCase(input)){
            System.out.println("验证码正确");
        }else {
            System.out.println("验证码错误");
        }

    }
}
